﻿@model Orchard.Autoroute.ViewModels.AutoroutePartEditViewModel
@using Orchard.Autoroute
@using Orchard.Mvc.Extensions
@using Orchard.Utility.Extensions;
@using Orchard.Environment.Configuration

@if(Model.Settings.DefaultPatternIndex == -1) {
    <div class="message message-Error">@T("The current Content Type does not have a default Autoroute Pattern. Please edit the settings first.")</div>
    return;
}

@{
    var defaultPattern = Model.Settings.Patterns[Model.Settings.DefaultPatternIndex];
    var urlPrefix = WorkContext.Resolve<ShellSettings>().RequestUrlPrefix;
    if (!String.IsNullOrWhiteSpace(urlPrefix)) {
        urlPrefix += "/";
    }
}

@if (!Model.PromoteToHomePage) {
    <fieldset class="permalink">
        <label>@T("Permalink")</label>
        @if (Model.Settings.AllowCustomPattern) {
            <span>@Url.MakeAbsolute("/")@urlPrefix</span>
            <span>@Html.TextBoxFor(m => m.CurrentUrl, new {@class = "text"})</span>
        }
        else {
            <span>@Url.MakeAbsolute("/")@urlPrefix</span>
        }

        <span class="hint">@T("Save the current item and leave the input empty to have it automatically generated using the pattern {0} e.g., {1}", defaultPattern.Name, defaultPattern.Description)</span>

    </fieldset>
    if (AuthorizedFor(Permissions.SetHomePage)) {
         <fieldset>
             <span class="checkbox-and-label">
                 @Html.EditorFor(m => m.PromoteToHomePage)
                 <label for="@Html.FieldIdFor(m => m.PromoteToHomePage)" class="forcheckbox">@T("Set as home page")</label>
             </span>
             <span class="hint">@T("Check to promote this content as the home page")</span>
         </fieldset>
     }
}
else {
    <span>@T("This content is the current home page")</span>
}
